<?php

/**
 * Description of TestController
 *
 * @author luigi.pastore
 * @created  10-mag-2011
 */
class TestController extends Classes_Controller
{
    public function init()
    {
//	echo "<pre>";
//	var_dump(  parse_url( 'http://asd/admin/ajax/list/events/selected/1:2/page/1/orderby/event_title:asc/per_page/10' ));
//	echo "</pre>";
//	exit();
	
		$this->model = new Classes_Post();

    }
    public function indexAction()
    {
        require_once(LIBRARY_PATH .'/fpdf/fpdf.php');

require_once(LIBRARY_PATH .'/fpdi/fpdi.php');

$pdf = new FPDI();

$pagecount = $pdf->setSourceFile(LIBRARY_PATH .'/form.pdf');


$pdf->addPage();
$pdf->useTemplate($tplidx, 10, 10, 90);

$pdf->Output('newpdf.pdf', 'D');
exit;
        
        
define('FPDF_FONTPATH',LIBRARY_PATH .'/fpdf/font/');
//questo file e la cartella font si trovano nella stessa directory
require(LIBRARY_PATH .'/fpdm/fpdm.php');
$fields = array(
    'name'    => 'My name',
    'address' => 'My address',
    'city'    => 'My city',
    'phone'   => 'My phone number'
);

$pdf = new FPDM(LIBRARY_PATH .'/fpdm/template.pdf');
$pdf->Load($fields, true); // second parameter: false if field values are in ISO-8859-1, true if UTF-8
$pdf->Merge();
$pdf->Output();
exit();

        $model = new Classes_TourbookSteps();
        
        echo "<pre>";
        var_dump($model->fetch(1, array(2,3)));
        echo "</pre>";
        exit;
        $model->fetchAll();
        
        $model->fetchById(array(1,2));
        
        
        echo "<pre>";
        var_dump($this->_db = Classes_MySqliLayer::getInstance());
        echo "</pre>";
        exit;
	$query	= $this->application->db->selectQuery( array(
		    'from' => 'fab_artists',
		    'fields' => '*, COUNT(artist_id) AS MAX',
		    'where' => array( 'artist_id' => array(1) )
	    ) );

	while( $contact = $this->application->db->fetch( $query ) )
	{
	    $ret[$contact['fab_partners_partner_id']]['partner_contacts'][] = $contact;
            echo "<pre>";
            var_dump($contact);
            echo "</pre>";
            exit;
	}
            // Mapping...
            $data = array(
                'activity_id'           => 'asd',
                'activity_title'        => $this->form_data['activity_title'],
                'activity_status'       => 1,
                'activity_description'  => $this->form_data['activity_description'],
                'activity_assignedto'   => $this->form_data['activity_assignedto'],
                'activity_start_date'   => '',
                'activity_end_date'     => '2012-01-1',
                'activity_start_time'   => '',
                'activity_end_time'     => '22:00',
                'activity_createdby'    => 1
                );
            
	$this->model_activity = new Classes_Activity($data);

       
        echo "<pre>";
        var_dump($this->model_activity->save());
        echo "</pre>";
        exit;
        
//        $str = '40100';
//        echo "<pre>";
//        var_dump(preg_match("/[0-9]{5}$/", $str));
//        var_dump((preg_match("/[0-9]{5}$/", $str) == 0 )? false : true);
//        echo "</pre>";
//        exit;
//        echo "<pre>";
//        var_dump(!(2 & MYSQLI_NOT_NULL_FLAG));
//        echo "</pre>";
//        exit;
//        echo "<pre>";
//        var_dump(  filter_var( NULL, FILTER_VALIDATE_INT, array( 'options' => array( 'min_range' => 0, 'max_range' => 98100 ), 'flags' => FILTER_REQUIRE_SCALAR ) ) );
//        echo "</pre>";
//        exit;
//        $model = new Classes_Location;
//        
//        echo "<pre>";
//        var_dump($model->fetchById( array(1,2)));
//        echo "</pre>";
//        exit;
        
//                if( !is_numeric( $model->save(
//                            array('post_links' => 
//                                array(
//                                    array('link_post_id' => 2, 'link_url' => 'asdasd'))))))
//                {
//                    echo "<pre>ERrori";
//                    var_dump($model->errors);
//                    echo "</pre>";
//                    exit;
//                }
                ;
//
                $model = new Classes_Location(array(
                    //'location_id' => 12,
                    'location_name' => 'asd',
                    'location_cap' => 'asd'
                ));
                
                    if( is_numeric( $post_id = $model->save()->location_id ) )
                    {
                        echo "<pre>SALVATO";
                        var_dump($post_id);
                        echo "</pre>";
                        exit;
                    }
                
                else
                {
                    echo "Errors:<pre>";
                    var_dump($model->errors);
                    echo "</pre>";
                    exit;
                }
                
        
	$location = $this->model_location->fetchById( array( $_SESSION['Live']['Location'] ) );

	$this->layout->location = array_shift( $location );
		    $this->layout->data = $_SESSION['Live'];

		    // Format Data
		    $this->layout->data['start_day'] = $this->days[date( 'N', mktime( $hour, $minute, $second, $_SESSION['Live']['Info']['month'], $_SESSION['Live']['Info']['day'], $_SESSION['Live']['Info']['year'] ) )];
		    $this->layout->artists = $artists;
	
		    return $this->layout->content = array( 'script' => 'live/completed' );

    }
    
    public function paginationAction()
    {
	$this->model_post	= new Classes_Post();

//	
//	//EDIT these 4 variables
	$per_page = 5; //rows per page
//
//	//$this->layout->disableLayout( true );
//	$this->layout->posts = $this->model_post->fetchAll();
	$this->layout->pages = ceil($this->model_post->getCount()/$per_page);

	$this->layout->content = array( 'script' => 'test/pagination' );
    }

    public function jqueryAction()
    {
	$this->layout->content = array( 'script' => 'test/jquery' );	
    }

    public function searchAction()
    {
	$this->layout->content = array( 'script' => 'test/search' );	
    }
}